package com.windward.vii.web.controller;

import com.windward.vii.common.JsonResult;
import com.windward.vii.common.ResultCode;
import com.windward.vii.dao.entity.Report;
import com.windward.vii.dao.mapper.ReportMapper;
import com.windward.vii.service.UserTokenService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Controller
public class ReportController {

    @Resource
    ReportMapper reportMapper;
    @Resource
    UserTokenService userTokenService;

    @RequestMapping(value = "v1/api1/report", method = RequestMethod.POST)
    @ResponseBody
    public JsonResult report(@RequestParam Long targetUid,
                              @RequestHeader(value="token") String token) {
        if(targetUid <= 0) {
            return new JsonResult(ResultCode.PARAM_ERROR_CODE, "targetUid错误");
        }
        Report report = new Report();
        report.setReporterUid(userTokenService.getUidByToken(token));
        report.setTargetUid(targetUid);
        report.setCreateTime(new Date());
        int row = reportMapper.insertSelective(report);
        return row > 0 ? JsonResult.success() : JsonResult.error();
    }


}
